package com.gf.framework.rpcdemo.client.controller;

import com.gf.framework.common.result.R;
import com.gf.framework.dubbo.constant.DubboConst;
import com.gf.framework.rpcdemo.api.dto.Student;
import com.gf.framework.rpcdemo.api.dubboservice.StudentService;
import com.gf.framework.rpcdemo.api.model.RequestModel;
import com.gf.framework.rpcdemo.api.model.ResponseModel;
import com.gf.framework.rpcdemo.client.feign.IApiFeign;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author gaofei
 * @date 2022/5/25 19:57
 */
@RestController
@Api(tags = "测试")
public class StudentController {
    // 自定义的hash规则
    @DubboReference(loadbalance = DubboConst.gfhash, retries = 3)
    StudentService studentService;


    @PostMapping("add")
    public Boolean add(@RequestBody Student student) {
        return studentService.add(1, student);
    }

    @Resource
    IApiFeign iApiFeign;

    @GetMapping("hello")
    public R<String> hello() {
        return iApiFeign.hello();
    }


    @PostMapping("posttest")
    public R<ResponseModel> posttest(@RequestBody RequestModel requestModel) {
        return iApiFeign.posttest(requestModel);
    }
}
